/**
 * 主视图。
 */

// 查找顶级视图的索引
function findTopLevelViewIndex(viewId) {
    for(var i = 0; i < topLevelListModel.count; ++i){
        //console.debug("topLevelListModel[i]:", topLevelListModel.get(i).viewId);
        if(topLevelListModel.get(i).viewId == viewId) return i;
    }

    console.error("Unknown top level view name:", viewName);
    return -1;
}

// 切换顶级视图
function switchTopLevelView(viewId, index){
    if(typeof(index) === "undefined") {
        index = findTopLevelViewIndex(viewId);
    }

    var lastView = topLevelListModel.get(topLevelListView.currentIndex).viewId;
    var currentView = viewId;

    topLevelListView.currentIndex = index;

    // 动态执行JS代码，实现切换功能，eval尽量少用
    eval(lastView + ".visible = false;" + currentView + ".visible = true");
}

// 确定是否退出
function confirmSignout(){
    messageDialog.title = "退出";
    messageDialog.text = "确定退出当前登录用户?"
    messageDialog.icon = MessageDialog.Question
    messageDialog.standardButtons = StandardButton.Yes | StandardButton.No
    messageDialog.callback = signout;
    messageDialog.visible = true;
}

// 退出
function signout(){
    rootView.qsSignOut();

    rootView.hide();
    loginDialog.show();
}
